<!--
 Open MCT, Copyright (c) 2014-2018, United States Government
 as represented by the Administrator of the National Aeronautics and Space
 Administration. All rights reserved.

 Open MCT is licensed under the Apache License, Version 2.0 (the
 "License"); you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0.

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 License for the specific language governing permissions and limitations
 under the License.

 Open MCT includes source code licensed under additional open source
 licenses. See the Open Source Licenses file (LICENSES.md) included with
 this source code distribution or the Licensing information page available
 at runtime from the About dialog for additional information.
-->
<div class="gl-plot plot-legend-{{legend.get('position')}} {{legend.get('expanded')? 'plot-legend-expanded' : 'plot-legend-collapsed'}}">
    <div class="gl-plot-legend flex-elem l-flex-row"
         ng-class="{ 'hover-on-plot': !!highlights.length }"
         ng-show="legend.get('position') !== 'hidden'">
        <span class="view-control flex-elem"
            ng-class="{ expanded: legend.get('expanded') }"
            ng-click="legend.set('expanded', !legend.get('expanded'));">
        </span>

        <!-- COLLAPSED PLOT LEGEND -->
        <div class="plot-wrapper-collapsed-legend">
            <div class="plot-legend-item"
                  ng-repeat="series in series track by $index">
                <div class="plot-series-swatch-and-name">
                    <span class="plot-series-color-swatch"
                          ng-style="{ 'background-color': series.get('color').asHexString() }">
                    </span>
                    <span class="plot-series-name">{{ series.get('name') }}</span>
                </div>
                <div class="plot-series-value hover-value-enabled value-to-display-{{ legend.get('valueToShowWhenCollapsed') }} {{ series.closest.mctLimitState.cssClass }}"
                     ng-class="{ 'cursor-hover': (legend.get('valueToShowWhenCollapsed').indexOf('nearest') != -1) }"
                     ng-show="!!highlights.length && legend.get('valueToShowWhenCollapsed') !== 'none'">
                    {{ legend.get('valueToShowWhenCollapsed') === 'nearestValue' ?
                        series.formatY(series.closest) :
                        legend.get('valueToShowWhenCollapsed') === 'nearestTimestamp' ?
                             series.closest && series.formatX(series.closest) :
                             series.formatY(series.get('stats')[legend.get('valueToShowWhenCollapsed') + 'Point']);
                    }}
                </div>
            </div>
        </div>

        <!-- EXPANDED PLOT LEGEND -->
        <div class="plot-wrapper-expanded-legend flex-elem grows">
            <table>
                <thead>
                    <tr>
                        <th>Name</th>
                        <th ng-if="legend.get('showTimestampWhenExpanded')">
                            Timestamp
                        </th>
                        <th ng-if="legend.get('showValueWhenExpanded')">
                            Value
                        </th>
                        <th ng-if="legend.get('showMinimumWhenExpanded')"
                            class="mobile-hide">
                            Min
                        </th>
                        <th ng-if="legend.get('showMaximumWhenExpanded')"
                            class="mobile-hide">
                            Max
                        </th>
                    </tr>
                </thead>
                <tr ng-repeat="series in series" class="plot-legend-item">
                    <td class="plot-series-swatch-and-name">
                        <span class="plot-series-color-swatch"
                              ng-style="{ 'background-color': series.get('color').asHexString() }">
                        </span>
                        <span class="plot-series-name">{{ series.get('name') }}</span>
                    </td>

                    <td ng-if="legend.get('showTimestampWhenExpanded')">
                        <span class="plot-series-value cursor-hover hover-value-enabled">
                            {{ series.closest && series.formatX(series.closest) }}
                        </span>
                    </td>
                    <td ng-if="legend.get('showValueWhenExpanded')">
                        <span class="plot-series-value cursor-hover hover-value-enabled"
                              ng-class="series.closest.mctLimitState.cssClass">
                            {{ series.formatY(series.closest) }}
                        </span>
                    </td>
                    <td ng-if="legend.get('showMinimumWhenExpanded')"
                        class="mobile-hide">
                        <span class="plot-series-value">
                            {{ series.formatY(series.get('stats').minPoint) }}
                        </span>
                    </td>
                    <td ng-if="legend.get('showMaximumWhenExpanded')"
                        class="mobile-hide">
                        <span class="plot-series-value">
                            {{ series.formatY(series.get('stats').maxPoint) }}
                        </span>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <div class="plot-wrapper-axis-and-display-area flex-elem grows">
        <div class="gl-plot-axis-area gl-plot-y"
             ng-style="{
                 width: (tickWidth + 30) + 'px'
             }">

            <div class="gl-plot-label gl-plot-y-label">
                {{ yAxis.get('label') }}
            </div>

            <mct-ticks axis="yAxis">
                <div ng-repeat="tick in ticks track by tick.text"
                     class="gl-plot-tick gl-plot-y-tick-label"
                     ng-style="{ top: (100 * (max - tick.value) / interval) + '%' }"
                     title="{{:: tick.fullText || tick.text }}"
                     style="margin-top: -0.50em; direction: ltr;">
                    <span>{{:: tick.text}}</span>
                </div>
            </mct-ticks>
        </div>
        <div class="gl-plot-wrapper-display-area-and-x-axis"
             ng-style="{
                     left: (tickWidth + 30) + 'px'
                 }">
            <span class="t-object-alert t-alert-unsynced" title="This plot is not currently displaying the latest data. Reset Pan/zoom to return to view latest data."></span>
            <div class="gl-plot-display-area">
                <mct-ticks axis="xAxis">
                    <div class="gl-plot-hash hash-v"
                         ng-repeat="tick in ticks track by tick.value"
                         ng-style="{
                             right: (100 * (max - tick.value) / interval) + '%',
                             height: '100%'
                         }">
                     </div>
                </mct-ticks>


                <mct-ticks axis="yAxis">
                     <div class="gl-plot-hash hash-h"
                          ng-repeat="tick in ticks track by tick.value"
                          ng-style="{ bottom: (100 * (tick.value - min) / interval) + '%', width: '100%' }">
                     </div>
                </mct-ticks>


                <mct-chart config="config"
                           series="series"
                           rectangles="rectangles"
                           highlights="highlights"
                           the-x-axis="xAxis"
                           the-y-axis="yAxis">
                </mct-chart>

                <div class="h-local-controls h-local-controls-overlay-content"
                     ng-show="plotHistory.length">
                    <div class="l-btn-set">
                        <a class="s-button icon-arrow-left"
                           ng-click="plot.back()"
                           title="Restore previous pan/zoom">
                        </a>
                        <a class="s-button icon-reset"
                           ng-click="plot.clear()"
                           title="Reset pan/zoom">
                        </a>
                    </div>
                </div>

                <span class="t-wait-spinner loading" ng-show="plot.isRequestPending()">
                </span>

            </div>

            <div class="gl-plot-axis-area gl-plot-x"
                 ng-style="{
                     left: (tickWidth - 30) + 'px'
                 }">

                <mct-ticks axis="xAxis">
                     <div ng-repeat="tick in ticks track by tick.text"
                          class="gl-plot-tick gl-plot-x-tick-label"
                          ng-style="{
                              left: (100 * (tick.value - min) / interval) + '%'
                          }"
                          ng-title=":: tick.fullText || tick.text">
                         {{:: tick.text }}
                     </div>
                </mct-ticks>

                <div class="gl-plot-label gl-plot-x-label">
                    {{ xAxis.get('label') }}
                </div>
            </div>

        </div>
    </div>

</div>
